package starwars.example;

import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.util.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class Item implements IUpdateHandler {

	public Body body;
	public Sprite sprite;
	public String type;

	public Item(Body body) {
		this.body=body;
	}


	public Item(Field field, FixtureAtlas fAtlas, String type, int x, int y) {
		FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.9f);
		sprite=new Sprite(x,y,fAtlas.fdc.assets.get(type).mTextureRegion);
		body=PhysicsFactory.createPolygonBody(field,
											  sprite,
											  fAtlas.fdc.assets.get(type).shape,
											  BodyType.DynamicBody,
											  FIXTURE_DEF);
		this.type=type;
		field.add(this);
		field.scene.attachChild(sprite);
		
		sprite.registerUpdateHandler(this);
	}

	public Vector2 getLinearVelocity(){
		return body.getLinearVelocity();
	}

	public void setLinearVelocity(Vector2 velocity) {
		body.setLinearVelocity(velocity);
	}

	public Object getWorldCenter() {
		return body.getWorldCenter();
	}

	public void setTransform(Object worldCenter, float rotationInRad) {
		body.setTransform((Vector2) worldCenter,rotationInRad);
	}

	public void setLinearDamping(int i) {
		body.setLinearDamping(i);
		
	}

	public void setAngularDamping(int i) {
		body.setAngularDamping(i);
	}


	public void setRotation(float radToDeg) {
		sprite.setRotation(MathUtils.radToDeg(radToDeg));
	}


	public void onUpdate(float pSecondsElapsed) {}

	public void reset() {}
	

	public interface iCollectorHandler{
		void analyse(Item item);
	}
	
	public abstract class CollectionHandler implements iCollectorHandler{
	}
}
